*File runs analysis on the 1979 National Longitudinal Study of Youth for "Timing Matters" by Aaron Rosenthal and Christina Farhart

*Reading in the data
	
	use Timing_Matters_NLSY79_Analysis.dta, clear	

*Survey setting the data

	svyset [pw=SAMPWEIGHT_2008]	
	
*Labeling the variables
	
	label var POLICE_TIMES_STOP "# of times stopped by Police"
	label var POLICE_0_14 "Stopped 1st before 15"
	label var POLICE_15_18 "Stopped 1st btw. 15-18"
	label var POLICE_19_25 "Stopped 1st after 18"
	label var INCOME_2008 "Adult Income"
	label var EMPLOYED_FT "Employed Full Time"
	label var EDUCATION "Educational Attainment"
	label var MARSTAT_COL_2008 "Married"
	label var FEMALE "Female"
	label var WHITE "White"
	label var AGE_1981 "Age"
	label var REPUB "Republican"
	label var DEM "Democrat"
	label var INCOME_1980 "Household Income Growing Up"
	label var PARENT_EDUCATION "Parental Education"

*Creating histogram for right side panel of Figure 1
	
	histogram POLICE_AGE_CONT, ylabel(0(5)20) discrete percent xtitle(Age) xlabel(0(2)26) scheme(s1mono) /// 
	title("NLSY") kdensity
	graph save NLSY_Histogram_Age_Contact.gph, replace				
	graph export NLSY_Histogram_Age_Contact.pdf, replace	
	
*Running models for Table 1- no age variables included
	
	*Model 1.2
	svy: logit VOTE POLICE_TIMES_STOP INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store vote
	
	*Model 1.4
	svy: reg POL_INTEREST_ORD POLICE_TIMES_STOP INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store interest
	
	esttab vote interest, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_Table1.rtf, replace		
		
*Running models for Table 2- bringing in age of first contact variables
			
	*Model 2.2
	svy: logit VOTE POLICE_0_14 POLICE_15_18 POLICE_19_25 POLICE_TIMES_STOP /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store vote_cls
	
	*Model 2.4
	svy: reg POL_INTEREST_ORD POLICE_0_14 POLICE_15_18 POLICE_19_25 POLICE_TIMES_STOP /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store interest_cls

	esttab vote_cls interest_cls, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_Table2.rtf, replace		
	

*Creating margins plot for right side panel of Figure 2	
	
	svy: reg POL_INTEREST_ORD POLICE_TIMES_STOP INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION /// 
	i.POLICE_AGE_CAT	
	margins POLICE_AGE_CAT
	marginsplot, recast(bar) ylabel(2(.5)4) ///
	xlabel(1 "Never Stopped" 2 "Before 15" 3 "Between 15-18" 4 "After 18", labsize(small)) ///
	xtitle("Age When First Stopped by Police") ytitle(Predicted Level of Interest in Politics) title("Political Interest, NLSY") scheme(s1mono)
	graph save NLSY_Pol_Interest.gph, replace
	graph export NLSY_Pol_Interest.pdf, replace
		
*Supplemental Appendix

	*Summary statistics for Table A1	
		tab VOTE
		tab POLICE_AGE_CONT	
		sum POL_INTEREST_ORD
		tab POLICE_EVER_STOP
		sum POLICE_TIMES_STOP
		tab POLICE_0_14 
		tab POLICE_15_17 
		tab POLICE_18_21 
		tab POLICE_22_older
		mean INCOME_2008
		tab EMPLOYED_FT
		tab EDUCATION
		tab MARSTAT_COL_2008 
		tab FEMALE 
		tab WHITE 
		tab BLACK
		mean AGE_1981 
		tab REPUB 
		tab DEM 
		mean INCOME_1980 
		mean PARENT_EDUCATION

*Running models for Table A2- using ordinal logistic regression for political interest

	*Model A2.1
	ologit POL_INTEREST_ORD POLICE_TIMES_STOP INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store interest_app

	*Model A2.2
	ologit POL_INTEREST_ORD POLICE_0_14 POLICE_15_18 POLICE_19_25 POLICE_TIMES_STOP /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store interest_cls_app
		
	esttab interest_app interest_cls_app, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_TableA2.rtf, replace		
	
*Running models for Tables A3 and A4- excluding survey weights

	*Model A3.2
	logit VOTE POLICE_TIMES_STOP INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store vote_app
	
	*Model A3.4
	reg POL_INTEREST_ORD POLICE_TIMES_STOP INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store interest_app
	
	esttab vote_app interest_app, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_TableA3.rtf, replace		
			
	*Model A4.2
	logit VOTE POLICE_0_14 POLICE_15_18 POLICE_19_25 POLICE_TIMES_STOP /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store vote_cls_app
	
	*Model A4.4
	reg POL_INTEREST_ORD POLICE_0_14 POLICE_15_18 POLICE_19_25 POLICE_TIMES_STOP /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store interest_cls_app
	
	esttab vote_cls_app interest_cls_app, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_TableA4.rtf, replace		
				
*Running model for Table A5- predicting number of times stopped based on age of first contact
	
	*Model A5.2
	reg POLICE_TIMES_STOP POLICE_0_14 POLICE_15_18 /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION if POLICE_TIMES_STOP>0
	estimates store scale
	
	esttab scale, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_TableA5.rtf, replace		
		
*Running model for Table A6- interacting age of contact with frequency of contact					
		
	*Model A6.2
	reg POL_INTEREST_ORD POLICE_0_14##c.POLICE_TIMES_STOP POLICE_15_18 POLICE_19_25 /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION	
	estimates store scale_interaction
	
	esttab scale_interaction, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_TableA6.rtf, replace		
		
*Running models for Table A7- welfare receipt as an additional control

	*Model A7.2
	svy: logit VOTE POLICE_0_14 POLICE_15_18 POLICE_19_25 PARENT_WELFARE WELFARE POLICE_TIMES_STOP /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store vote_welfare
	
	*Model A7.4	
	svy: reg POL_INTEREST_ORD POLICE_0_14 POLICE_15_18 POLICE_19_25 PARENT_WELFARE WELFARE POLICE_TIMES_STOP /// 
	INCOME_2008 EMPLOYED_FT EDUCATION MARSTAT_COL_2008 FEMALE WHITE AGE_1981 REPUB DEM INCOME_1980 PARENT_EDUCATION
	est store interest_welfare
		
	esttab vote_welfare interest_welfare, starlevels(^ .1 * 0.05 ** .01 *** .001) ///
	cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons constant), using NLSY_TableA7.rtf, replace
					
